package com.bysj.lms.service.impl;

import com.bysj.lms.pojo.entity.DictionaryType;
import com.bysj.lms.mapper.DictionaryTypeMapper;
import com.bysj.lms.service.IDictionaryTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaojiakai
 * @since 2022-02-04
 */
@Service
public class DictionaryTypeServiceImpl extends ServiceImpl<DictionaryTypeMapper, DictionaryType> implements IDictionaryTypeService {

    @Autowired
    DictionaryTypeMapper dictionaryTypeMapper;

    @Override
    public PageInfo findByPage(String name, int page, int count) {
        PageHelper.startPage(page,count);
        List<DictionaryType> list = lambdaQuery().like(StringUtils.isNotBlank(name) && StringUtils.isNotEmpty(name), DictionaryType::getType, name)
                .eq(DictionaryType::getStatus, 0).list();
        return new PageInfo(list);
    }

    @Override
    public boolean updateStatus(int id,int status) {
        boolean update = lambdaUpdate().eq(DictionaryType::getId, id).set(DictionaryType::getStatus, status).update();
        return update;
    }

    @Override
    public DictionaryType findByType(String type) {
        DictionaryType dictionaryType = lambdaQuery().eq(DictionaryType::getType, type).one();
        return dictionaryType;
    }
}
